home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <io.h>
- #include <process.h>
-
- main()
- {
- int mono,escape,item,code,code1,code2,code3,i,c,j;
- char *sub_dir,subdir[20],label[80],file[30],temp[20];
- FILE *f1,*f2;
-
-
- mono = hardware(0); /* check for a color card */
-
- copyrite("PINSTALL\0","April 1986\0",mono);
- cls();
- printf("PRINT Printer Installation Routine\n\n");
-
- /* Check for an existing configuration file. If it exists, show it to
- them and find out if they want to replace it.
- */
-
- strncpy(file,"printer.cnf\0",13); /* set up the config file name */
- sub_dir = getenv("PRINT"); /* find the environmnet variable for print */
- strncpy(subdir,sub_dir,20);
- i=strlen(subdir);
- if ((subdir[i-1] !=92)&& (i>0)) {
- subdir[i] = 92; /* put in a backslash */
- ++i;
- }
- for (j=0; j<12; j++)
- subdir[i++] = file[j]; /* copy the rest of the name to it */
-
-
- if ((f1=fopen(subdir,"r")) != NULL) {
- printf("Printer configuration file already exists:\n\n");
- fgets(label,80,f1); /* get the printer label */
- printf("\n\nConfiguration for: %s\n",label);
-
- item = 1;
- while ((c=getc(f1)) != EOF) {
- ungetc(c,f1);
- fgets(temp,20,f1); /* get the first label */
- i=0;
- while (temp[i++] != '\n');
- temp[i-1] = ' '; /* get rid of the carriage return */
- for (c=i; c<20; c++)
- temp[c] = ' ';
- temp[20] = '\0'; /* pad out to 20 characters for display purposes */
-
- fscanf(f1,"%d %d %d %d",&escape,&code1,&code2,&code3);
- printf("<%2d> %s %2d %2d %2d <",item,temp,code1,code2,code3);
- if (escape == 0)
- printf("No leading escape (ASCII 27)>\n");
- else
- printf(" Leading escape (ASCII 27)>\n");
- ++item;
- }
- fclose(f1);
-
- printf("\n\nDo you wish to overwrite (replace) this data (y/n)? ");
- while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
- printf("\n\n");
-
- if ((c=='n') || (c=='N')) {
- printf("\n\nAborting PINSTALL procedure\n\n");
- exit(0);
- }
- else {
- c=unlink(subdir);
- if (c != NULL) {
- printf("\n");
- cprint("Error: Unable to delete old configuration file",131);
- printf("\n\n");
- exit(1);
- }
- }
- } /* end of if fopen != NULL) */
- printf("Ready for new printer parameters\n\n");
- printf("You may enter up to 7 different printer configuration codes\n");
- printf("for your printer. You will be asked for a name for each\n");
- printf("configuration codes, and then for up to three character codes\n");
- printf("(exclusive of the escape code) to transmit to the printer.\n\n");
- printf("You will be prompted for the printer codes to handle enhanced\n");
- printf("print mode, return to normal print mode from enhance, and for\n");
- printf("a printer initialization string.\n\n");
-
-
- code = 0;
- item = 1;
- printf("\nWhat printer is this for: ");
- i=0;
- while (((label[i++] = getche()) != 13) && (i<60)) {
- if (label[i-1] == 8)
- i -=2; /* backspace for them */
- }
- label[i-1] = '\0';
-
- while (code == 0) {
- if (item == 1) {
- printf("\nEnter your printer codes for ");
- cprint("printer initialization",131);
- strncpy(temp,"Printer Initialize\0",20);
- printf("\n");
- }
-
- if (item == 2) {
- printf("\nEnter your printer codes for ");
- cprint("enhanced mode",131);
- strncpy(temp,"Enhanced mode\0",20);
- printf("\n");
- }
-
- if (item == 3) {
- printf("\nEnter your printer codes for ");
- cprint("switch from enhanced to normal mode ",131);
- strncpy(temp,"Return to normal\0",20);
- printf("\n");
- }
-
- if (item >3) {
- printf("\nEnter the label for configuration code %3d ",item);
- printf("+--------------------+\n");
- printf( " ");
- i=1;
- temp[0] = ' '; /* put in a leading space */
- while (((temp[i++]=getche()) != 13) && (i<20)) {
- if (temp[i-1] == 8)
- i -=2; /* backspace */
- }
- temp[i-1] = '\0'; /* put the eos marker on it */
- }
-
- printf("\nDoes this code sequence require a leading escape (ASCII 27)? ");
- while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
-
- if ((c=='y') || (c=='Y'))
- escape = 1;
- else
- escape = 0;
-
- printf("\nYou may now enter up to three ascii codes to be transmitted\n");
- printf("to your printer for this function. Enter 0 for any codes you\n");
- printf("do not wish to use.\n\n");
-
- printf("Enter ascii code 1: ");
- scanf("%d",&code1);
- printf("Enter ascii code 2: ");
- scanf("%d",&code2);
- printf("Enter ascii code 3: ");
- scanf("%d",&code3);
-
- printf("You have entered:\n\n");
- printf("Label: ");
- if (escape == 1)
- printf(" %s\nPrinter Code: 27 ",temp);
- else
- printf("%s\nPrinter Code: ",temp);
- printf("%d %d %d\n\nIs this correct (y/n)? ",code1,code2,code3);
-
- while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
- printf("\n\n");
-
- if ((c=='y') || (c=='Y')) { /* write the code to the file */
- if ((f1=fopen(subdir,"a")) != NULL) {
- if (item == 1)
- fprintf(f1,"%s\n",label);
-
- fprintf(f1,"%s\n",temp);
- fprintf(f1,"%d %d %d %d",escape,code1,code2,code3);
- fclose(f1);
- }
- else {
- printf("\n");
- cprint("Error on open. Aborting,131");
- printf("\n\n");
- exit(1);
- }
- }
- else
- --item;
-
- if (((item <=10)&& (item >2)) && ((c=='y') || (c=='Y'))) {
-
- printf("Do you wish to enter more (y/n)? ");
- while (((c=getch()) != 'y') && (c != 'Y') && (c !='n') && (c !='N'));
-
- if ((c=='n') || (c=='N'))
- code = 1; /* set up for the exit */
- }
- ++item;
-
- } /* end of while code == 0 */
-
- printf("\n\nPrinter initialization completed\n\n");
- printf("\n\nReminder: Don't forget to set the environment variable\n");
- printf(" if you have created this configuration in a directory\n");
- printf(" other than the root directory.\n\nExample:\n");
- printf(" If you created it in the \UTIL directory, you would add a\n");
- printf(" line to your AUTOEXEC.BAT file as follows:\n\n");
- printf(" SET PRINT=C:\UTIL\n\n");
-
- } /* end of main */
-